package edu.xust.service.impl;

import edu.xust.config.Resource;
import edu.xust.config.Service;
import edu.xust.dao.PostServiceDao;
import edu.xust.dto.BaseDto;
import edu.xust.dto.MessageEnum;
import edu.xust.entity.PostServiceBean;
import edu.xust.service.PostService;

import java.util.List;
import java.util.Optional;

@Service("postService")
public class PostServiceImpl implements PostService {

    @Resource
    private PostServiceDao postServiceDao;

    @Override
    public BaseDto getPostServiceBeanByPID(Integer pid) {
        PostServiceBean bean = postServiceDao.getPostServiceBeanByPID(1000);
        Optional<PostServiceBean> op = Optional.ofNullable(bean);
        MessageEnum messageEnum = op.isPresent() ? MessageEnum.FINDPOSTSERVICEBYPIDSUCCESS : MessageEnum.FINDPOSTSERVICEBYPIDFAIL;
        return new BaseDto(messageEnum, bean);
    }

    @Override
    public BaseDto getAllPostServiceBean() {
        List<PostServiceBean> beans = postServiceDao.getPostAllServiceBean();
        Optional<List<PostServiceBean>> op = Optional.ofNullable(beans);
        MessageEnum messageEnum = op.isPresent() ? MessageEnum.FINDALLPOSTSERVICESUCCESS : MessageEnum.FINDPOSTSERVICEBYPIDFAIL;
        return new BaseDto(messageEnum, beans);
    }
}
